package co2.bean;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import co2.engine.DAOInterface;
import co2.pojos.HasilTest;
import co2.pojos.Material;
import co2.pojos.PaketSoal;

@ManagedBean
@ViewScoped
public class HasilTestBean extends AbstractBean implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private List<HasilTest> list;
	private List<PaketSoal> listPs;
	private String psId;
	private HasilTest ht;;
	
	
	@Autowired
	@Qualifier("daoI")
	private DAOInterface dao;
	
	
	@PostConstruct
	public void postCon(){
		listPs = dao.getAllPaketSoal();
		droplistChange();
	}
	
	public void delete(){
		try{
			dao.delete(HasilTest.class, ht.getId());
			droplistChange();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Item Deleted",""));
		}catch(Exception e){
			e.printStackTrace();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Delete Fail",""));

		}
	}
	public void droplistChange(){
		if(psId!=null){
			list = dao.getAllByPaketSoalId(psId);
		}
	}

	public List<HasilTest> getList() {
		return list;
	}

	public void setList(List<HasilTest> list) {
		this.list = list;
	}

	public List<PaketSoal> getListPs() {
		return listPs;
	}

	public void setListPs(List<PaketSoal> listPs) {
		this.listPs = listPs;
	}

	public String getPsId() {
		return psId;
	}

	public void setPsId(String psId) {
		this.psId = psId;
	}

	public DAOInterface getDao() {
		return dao;
	}

	public void setDao(DAOInterface dao) {
		this.dao = dao;
	}

	public HasilTest getHt() {
		return ht;
	}

	public void setHt(HasilTest ht) {
		this.ht = ht;
	}

}
